package com.zhouchb.test;

import javax.xml.bind.SchemaOutputResolver;

/**
 * @Create 2023-06-19 21:50
 * @Description
 */
public class 死锁 {
   static  Object lockA = new Object();
    static  Object lockB = new Object();

    public static void main(String[] args) {

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lockA){
                    System.out.println("获取锁A");
                    System.out.println("-----------尝试获取锁B");
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (lockB){
                        System.out.println("=====获取到锁B");
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lockB){
                    System.out.println("获取锁B");
                    System.out.println("-----------尝试获取锁A");
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (lockA){
                        System.out.println("=====获取到锁A");
                    }
                }
            }
        }).start();
    }
}
